﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>其他培训</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/lib/layui/css/layui.css" media="all">
    <script src="~/lib/layui/layui.js" charset="utf-8"></script>
</head>
<body>
        <form lay-filter="qtpx" class="layui-form layui-form-pane" action="">
            <input type="hidden" name="id">
            <input type="hidden" name="jbxxid">

            <div class="layui-form-item">
            <!--培训时间-->
                <div class="layui-inline">
                    <label class="layui-form-label">培训时间:</label>
                    <div class="layui-input-inline">
                    <input type="text" name="pxdate" class="layui-input" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">
            <!--培训主题-->
            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label">培训主题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pxname" class="layui-input">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <!--培训讲师-->
            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label">培训讲师</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pxr" class="layui-input">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <div class="layui-form-item">
                  <button type="button" class="layui-btn" id="Save_qtpx">保存</button>
            </div>
            <hr class="layui-border-green">
        </form>
        <script>
        layui.use(['form', 'util', 'laydate', 'dropdown'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var util = layui.util;
            var dropdown = layui.dropdown;
            var laydate = layui.laydate;

            //初始赋值
            var url = location.search; 
            if (url.indexOf("?") != -1) {  
                var id = getQueryVariable('id');
                var jbxxid = getQueryVariable('jbxxid');

                if(id!=null)
                {
                    var data = getqtpxData("", id);

                    form.val('qtpx', {
                        "id": id,
                        "jbxxid": data[0].jbxxid,
                        "pxdate": data[0].pxdate,
                        "pxname": data[0].pxname,
                        "pxr": data[0].pxr
                    });

                    laydate.render({
                        elem: '#pxtime'
                        , value: data[0].pxdate
                    });
                }else
                {
                    form.val('qtpx', {
                        "jbxxid": jbxxid
                    });

                    laydate.render({
                        elem: '#pxtime'
                        , value: getNow()
                    });              
                }

            }

            //其他培训保存
            layui.$('#Save_qtpx').on('click', function () {
                var data = form.val('qtpx'); 
                
                if(data.jbxxid==""){
                    layer.msg("请先保存基本信息！");
                    return;
                }

                var opurl = "/HmcWH/Save_qtpx";

                if (form.val('qtpx').id != "") {
                    opurl = "/HmcWH/Update_qtpx";
                } else {
                    form.val('qtpx', {
                        "id": guiid()
                    });
                }
                data = form.val('qtpx');
                                            
                $.ajax({
                    url: opurl,
                    type: "post",
                    async: false,
                    data: data,
                    success: function (result) {
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg(result, { time: 1000 });
                        if (result == "保存成功！" || result == "修改成功！" ) {
                            //刷新父级表格
                            parent.layui.table.reload('qtpx', {
                                data: getqtpxData(data.jbxxid, "")
                            }); 
                        }
                        if(result=="保存失败！"){
                            form.val('qtpx', {
                                "id": ""
                            });
                            return;
                        }
                        parent.layer.close(index);
                    }
                });                                              
            });
        });

        function getOrgTreeData() {
            var data = [];
            $.ajax({
                url: "/TreeData/GetOrgTreeDatanew",
                type: "post",
                async: false,
                success: function (resut) {
                    data = resut;
                }
            });
            return data;
        }

        function guiid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
                function (c) {
                    var r = (Math.random() * 16) | 0,
                        v = c == 'x' ? r : (r & 0x3) | 0x8;
                    return v.toString(16);
                }
            );
        }

        function getqtpxData(jbxxid, qtpxid) {
            var data = [];
            $.ajax({
                url: "/HmcWH/get_qtpx",
                type: "post",
                async: false,
                data: { "jbxxid": jbxxid,"qtpxid":qtpxid },
                success: function (resut) {
                    data = resut;
                }
            });
            return data;
        }

        function getNow() {
            var nowdate = new Date();
            var year = nowdate.getFullYear(),
                month = nowdate.getMonth() + 1,
                date = nowdate.getDate();

            return year + "-" + month + "-" + date;
        }

        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return pair[1]; }
            }
            return null;
        }
        </script>

</body>
</html>